<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />

    <script src="../libraries/RGraph.svg.common.core.js" ></script>
    <script src="../libraries/RGraph.svg.bar.js" ></script>
    

    <title>RGraph demo: An SVG Bar chart showing the UK inflation rate</title>
    
    <meta name="robots" content="noindex,nofollow" />
    <meta name="description" content="An SVG Bar chart showing the UK inflation rate" />
</head>
<body>


    <h1>An SVG Bar chart showing the UK inflation rate</h1>









    <div style="width: 750px; height: 300px" id="chart-container"></div>



    <div id="fb-root"></div>
    <script>
        function loadFB (d)
        {
            var js, fjs = document.getElementsByTagName('script')[0];
            if (document.getElementById('facebook-jssdk')) {
                return;
            }
            
            js     = document.createElement('script');
            js.id  = 'facebook-jssdk';
            js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.8";
            
            fjs.parentNode.insertBefore(js, fjs);
        }
        
        
        setTimeout(loadFB, 1500);
    </script>
    
    <style>
        div#sharePopup {
            display: inline-block;
            color: white;
            z-index: 2;
            min-width: 575px;
            height: 40px;
            margin-left: 100px;
            margin-top: 20px;
            margin-bottom: 20px;
            box-shadow: 1px -1px 2px #aaa;
            background-color: rgba(0,0,0,0.75);
            text-align: center;
            font-weight: bold;
            border-radius: 10px;
        }
    
        div#sharePopup span#label {
            position: relative;
            top: 5px;
        }
        
        div#sharePopup div.fb-like {
            text-align: center;
            display: inline-block;
            position: relative;
            top: 4px;
        }
    </style>
    
    <div id="sharePopup">
        <span id="label">If you like RGraph please share it:</span>
        <span style="display: inline-block; min-width: 225px">
            <div class="fb-like" data-href="https://www.rgraph.net" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>
            <a href="javascript: null" onclick="window.open('http://www.twitter.com/share?url=https://www.rgraph.net&text=HTML5%20charts%20for%20the%20web%20with%20@_RGraph%20', 'twitter-sharer-window', 'top=50,left=50,width=700,height=300')"><img src="/images/twitter-60x20.png"  style="transform: translate(10px, 8px); box-shadow: 1px 1px 1px gray" border="0" /></a>
        </span>
    </div>



    <script>
        // This is the source data
        data = {            
            source: [
                {rate: 2.3, label: 'Mar 2017'},
                {rate: 2.3, label: 'Feb 2017'},
                {rate: 1.8, label: 'Jan 2017'},
                {rate: 1.6, label: 'Dec 2016'},
                {rate: 0.9, label: 'Oct 2016'},
                {rate: 1.2, label: 'Nov 2016'},
                {rate: 1.0, label: 'Sep 2016'},
                {rate: 0.6, label: 'Aug 2016'},
                {rate: 0.6, label: 'Jul 2016'},
                {rate: 0.5, label: 'Jun 2016'},
                {rate: 0.3, label: 'May 2016'},
                {rate: 0.3, label: 'Apr 2016'}
            ],
            
            // These are for once the data has been extracted and split up from
            // the source
            data:   [],
            labels: []
        };

        // Reverse the data so that the latest figure is on the right
        data.source = RGraph.SVG.arrayReverse(data.source);
        
        
        // Loop through the source data extracting the required parts
        for (var i=0; i<data.source.length; ++i) {
            if (data.source[i]) {
                
                // Extract the data piece from the source data
                data.data[i] = data.source[i].rate;
    
                // Extract the label from the source data
                data.labels[i] = ((i+1) % 3 === 0 ? data.source[i].label : '');
            }
        }




        new RGraph.SVG.Bar({
            id: 'chart-container',
            data: data['data'],
            options: {
                xaxisLabels: data['labels'],
                colors: ['Gradient(#4B86B6:#4B86B6:white)'],
                strokestyle: 'black',
                textFont: 'Monospace',
                textSize: 10,
                hmargin: 8,
                backgroundGridColor: '#eee',
                backgroundGridVlines: false,
                backgroundGridBorder: false,
                yaxis: false,
                xaxis: false,
                yaxisDecimals: 1,
                labelsAbove: true,
                labelsAboveDecimals: 1,
                title: 'UK inflation rate',
                titleSize: 10,
                titleHalign: 'left',
                titleX: 50,
                yaxisMax: 2.5,
                linewidth: 0.75
            }
        }).draw();
    </script>



    <p></p>

    This goes in the documents header:
    <pre class="code">
&lt;script src="RGraph.svg.common.core.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.svg.bar.js"&gt;&lt;/script&gt;
</pre>
    
    Put this where you want the chart to show up:
    <pre class="code">
&lt;div style="width: 750px; height: 300px" id="chart-container"&gt;&lt;/div&gt;
</pre>

    This is the code that generates the chart:
    <pre class="code">
&lt;script&gt;
    <span>// This is the source data</span>
    data = {            
        source: [
            {rate: 2.3, label: 'Feb 2017'},
            {rate: 1.8, label: 'Jan 2017'},
            {rate: 1.6, label: 'Dec 2016'},
            {rate: 0.9, label: 'Oct 2016'},
            {rate: 1.2, label: 'Nov 2016'},
            {rate: 1.0, label: 'Sep 2016'},
            {rate: 0.6, label: 'Aug 2016'},
            {rate: 0.6, label: 'Jul 2016'},
            {rate: 0.5, label: 'Jun 2016'},
            {rate: 0.3, label: 'May 2016'},
            {rate: 0.3, label: 'Apr 2016'},
            {rate: 0.5, label: 'Mar 2016'}
        ],
        
        <span>// These are for once the data has been extracted and split up from
        // the source</span>
        data:   [],
        labels: []
    };

    // Reverse the data so that the latest figure is on the right
    data.source = RGraph.SVG.arrayReverse(data.source);
    
    
    <span>// Loop through the source data extracting the required parts</span>
    for (var i=0; i&lt;data.source.length; ++i) {
        if (data.source[i]) {
            
            <span>// Extract the data piece from the source data</span>
            data.data[i] = data.source[i].rate;

            <span>// Extract the label from the source data</span>
            data.labels[i] = ((i+1) % 3 === 0 ? data.source[i].label : '');
        }
    }




    new RGraph.SVG.Bar({
        id: 'chart-container',
        data: data['data'],
        options: {
            xaxisLabels: data['labels'],
            colors: ['Gradient(#4F88B8:white)'],
            strokestyle: 'black',
            textFont: 'Monospace',
            textSize: 10,
            yaxisMax: 2.5,
            hmargin: 8,
            backgroundGridColor: '#eee',
            backgroundGridVlines: false,
            backgroundGridBorder: false,
            yaxis: false,
            xaxis: false,
            yaxisDecimals: 1,
            labelsAbove: true,
            labelsAboveDecimals: 1,
            title: 'UK inflation rate',
            titleSize: 10,
            titleHalign: 'left',
            titleX: 50,
            linewidth: 0.75
        }
    }).draw();
&lt;/script&gt;
</pre>



    
    

    <p>
        <a href="./#svg">&laquo; Back</a>
    </p>

</body>
</html>